<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运动员数据管理</title>

</head>
<script type="text/javascript" src="../res/layui/layui.js"></script>
<script type="text/javascript" src="../res/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="../res/js/Tools.js"></script>
<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">

<script type="text/javascript">
    $.ajaxSetup({
        async:false
    });
</script>
<style type="text/css">
    #usPoto{ margin:10px auto;
        position: absolute;
        top: 150px;
        left: 200px;
    }
    #usPoto img{ border-radius:50%}
</style>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>运动员信息管理</legend>
</fieldset>

<form class="layui-form" action="" id = "form" name="form">
    <!-- 运动员ID -->
    <div style="display: none;">
        <input type="text" name="athleteId" id="athleteId"  autocomplete="off" placeholder="运动员ID" class="layui-input">
    <!-- 用户ID -->
        <input type="text" name="usId" id="usId"  autocomplete="off" placeholder="用户ID" class="layui-input">
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">运动员姓名</label>
        <div class="layui-input-block">
            <input type="text" name="athleteName" id="athleteName"  autocomplete="off" placeholder="请输入运动员姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">家庭住址</label>
        <div class="layui-input-block">
            <input type="text" name="addr" id="addr" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input type="tel" name="phone" id="phone" placeholder="联系电话" lay-verify="required|phone" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="usEmail" id="usEmail" placeholder="邮箱" lay-verify="email" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
                <input type="text" name="deptName" id="deptName" placeholder="部门名称" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">岗位</label>
            <div class="layui-input-block">
                <input type="text" name="postName" id="postName" placeholder="岗位名称" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">注册单位</label>
            <div class="layui-input-inline">
                <input type="text" name="organName" id="organName" placeholder="注册单位" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登陆账号</label>
            <div class="layui-input-block">
                <input type="text" name="usName" id="usName" placeholder="登陆账号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div id = "userPoto" class="layui-inline">
            <label class="layui-form-label">账号头像</label>
            <div class="layui-input-block whstandard">
                <button type="button" class="layui-btn" id="test1">
                    <i class="layui-icon">&#xe67c;</i>点击上传图片
                </button>
            </div>
        </div>
    </div>
    <div id="usPoto" class="layui-form-item">

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登陆密码</label>
        <div class="layui-input-inline">
            <input type="password" name="usPass" id="usPass" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6~12位密码</div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">毕业院校</label>
            <div class="layui-input-inline">
                <input type="text" name="graduateSchool" id="graduateSchool" placeholder="毕业院校" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">籍贯</label>
            <div class="layui-input-inline">
                <input type="text" name="nativePlace" id="nativePlace" placeholder="籍贯" autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">现教练</label>
            <div class="layui-input-block">
                <select name="coachId" id="coachId" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">原教练</label>
            <div class="layui-input-block">
                <select name="oldCoach" id="oldCoach"  lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
                <div class="layui-form-mid layui-word-aux">没有选择原教练则默认选择</div>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">所在体育项</label>
            <div class="layui-input-block">
                <select name="sportId" id="sportId">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="athleteSex" id="man" value="男" title="男" checked>
            <input type="radio" name="athleteSex" id="woman" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">习惯手</label>
        <div class="layui-input-block">
            <input type="radio" name="hand" id="left" value="左手" title="左手" >
            <input type="radio" name="hand" id="right" value="右手" title="右手" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">出生年月</label>
            <div class="layui-input-block">
                <input type="text" name="birthday" id="birthday" placeholder="选择日期" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">打法</label>
        <div class="layui-input-inline">
            <input type="text" name="play" id="play" placeholder="简单描述打法" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">俱乐部</label>
        <div class="layui-input-inline">
            <input type="text" name="club" id="club" placeholder="俱乐部" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">进队时间</label>
            <div class="layui-input-block">
                <input type="text" name="joinTime" id="joinTime" placeholder="选择日期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">训练结束</label>
            <div class="layui-input-block">
                <input type="text" name="trainingYears" id="trainingYears" placeholder="选择日期" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">技术等级</label>
            <div class="layui-input-block">
                <select name="level" id="level" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">文化程度</label>
            <div class="layui-input-block">
                <select name="education" id="education" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">最好成绩</label>
            <div class="layui-input-block">
                <select name="bestResult" id="bestResult"  lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">家庭情况说明</label>
        <div class="layui-input-block">
            <textarea name="family" id="family" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">运动员说明</label>
        <div class="layui-input-block">
            <textarea name="athleteExp" id="athleteExp" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">技术特征</label>
        <div class="layui-input-block">
            <textarea name="technical" id="technical" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">战术特征</label>
        <div class="layui-input-block">
            <textarea name="tactics" id="tactics" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">心理特征</label>
        <div class="layui-input-block">
            <textarea name="mentality" id="mentality" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div id="resetbutton" class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter =  "act" >立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
    <script type="text/javascript">
        var form=null;
        //监听文件上传
        layui.use('upload', function(){
            var upload = layui.upload;
            //alert(JSON.stringify(formData));
            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,auto: false //选择文件后不自动上传
                ,bindAction: '#act' //指向一个按钮触发上传
                ,done: function(res){
                    //上传完毕回调
                    layer.msg(res.msg);
                    //关闭当前层
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                }
                ,error: function(){
                    //alert("文件上传异常");
                }
            });
        });
        //时间选择器
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //运动员生日
            laydate.render({
                elem: '#birthday' //指定元素
                ,trigger: 'click'
                ,isInitValue: true //是否填充初始值 是

            });
            //进队时间
            laydate.render({
                elem: '#joinTime' //指定元素
                ,trigger: 'click'
                ,isInitValue: true //是否填充初始值 是

            });
            //训练年限
            laydate.render({
                elem: '#trainingYears' //指定元素
                ,trigger: 'click'
                ,isInitValue: true //是否填充初始值 是

            });

        });


        layui.use('form', function() {
            form = layui.form;
            //监听提交按钮
            form.on('submit(act)', function(data){
                //layer.msg(JSON.stringify(data.field)); //弹出当前表单数据*!/
                var formData = new FormData(document.getElementById("form"));
                var url = "../AtsEmpAthleteAction/athleteUpdateOrAdd";
                $.ajax({
                    type:"post",
                    url:url,
                    data:formData,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.location.reload();
                        });

                }
            })
            form.render();
            return false;
        });

            loadingCoach();//加载教练
            loadingOlCoach();//加载原教练
            loadingSport();//加载体育项目
            loadingDic();//加载技术等级项
            loadingCulture();//加载文化程度项
            loadingResult();//加载最好成绩
            findByid();//加载个人数据
            closePage();//如果是更多信息，则是关闭
    });
        layui.use(['form', 'layedit', 'laydate'], function(){
            var layedit = layui.layedit,laydate = layui.laydate;
            //自定义
            form.verify({
                title: function(value){
                    if(value.length < 5){
                        return '标题至少得5个字符啊';
                    }
                }
                ,pass: [
                    /^[\S]{6,12}$/
                    ,'密码必须6到12位，且不能出现空格'
                ]
            });
        });

        function closePage(){
            $("#clospage").click(function(){
                //当你在iframe页面关闭自身时
                var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });
        }
        function loadingResult(){
            $.ajax({
                url: "../AtsEmpAthleteAction/loadingResult",
                type: "post",
                dataType: "json",
                data:{
                    dcode:4
                }
                ,
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $.each(data,function(index,item) {
                        $('#bestResult').append(new Option(item.dname, item.did));// 下拉菜单里添加元素
                    });
                    layui.form.render("select");//渲染下拉框
                }
            });
        }
        function loadingOlCoach(){
            $.ajax({
                url: "../AtsEmpAthleteAction/findAllCoach",
                type: "post",
                dataType: "json",
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $.each(data,function(index,item) {
                        // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                        $('#oldCoach').append(new Option(item.coachName, item.coachId));// 下拉菜单里添加元素

                    });
                    layui.form.render("select");//渲染下拉框
                }
            });
        }
        function loadingCulture(){
            $.ajax({
                url: "../AtsEmpAthleteAction/loadingCulture",
                type: "post",
                dataType: "json",
                data:{
                    dcode:3
                }
                ,
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $.each(data,function(index,item) {
                        // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                        $('#education').append(new Option(item.dname, item.did));// 下拉菜单里添加元素

                    });
                    layui.form.render("select");//渲染下拉框
                }
            });
        }
        function loadingDic(){
            $.ajax({
                url: "../AtsEmpAthleteAction/loadingDic",
                type: "post",
                dataType: "json",
                data:{
                 dcode:2
                }
                ,
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $.each(data,function(index,item) {
                        // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                        $('#level').append(new Option(item.dname, item.did));// 下拉菜单里添加元素

                    });
                    layui.form.render("select");//渲染下拉框
                }
            });
        }
        function loadingSport(){
            $.ajax({
                url: "../AtsEmpAthleteAction/findAllSport",
                type: "post",
                dataType: "json",
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $.each(data,function(index,item) {
                        // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                        $('#sportId').append(new Option(item.sportName, item.sportId));// 下拉菜单里添加元素

                    });
                    layui.form.render("select");//渲染下拉框
                }
            });
        }
        function loadingCoach(){
            $.ajax({
                url: "../AtsEmpAthleteAction/findAllCoach",
                type: "post",
                dataType: "json",
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $.each(data,function(index,item) {
                        // $("#expertSpecia").append("<option value='"+item.sportId+"'>"+ item.sportName+"</option>")
                        $('#coachId').append(new Option(item.coachName, item.coachId));// 下拉菜单里添加元素

                    });
                    layui.form.render("select");//渲染下拉框
                }
            });
        }
        function findByid(){
            //layer.msg("嗯哼~~");
            var id = getQueryString("id");
            var state = getQueryString("state");
            //alert(state);
            //alert("进入查询");
            if(id != null){
                $("#usName").attr("disabled",true);//限制账号
                $("#usPass").attr("disabled",true);//限制密码
            }
            var userPhto =null;
            $.ajax({
                url: "../AtsEmpAthleteAction/findById",
                type: "post",
                data: {
                    id: id
                },
                dataType: "json",
                // contentType: "application/json;charset=utf-8",
                success: function (data) {
                    $("#athleteId").val(data.athleteId);
                    $("#usId").val(data.usId);
                    $("#sportId").val(data.sportId);
                    $("#coachId").val(data.coachId);
                    $("#athleteName").val(data.athleteName);
                    $("#deptName").val(data.deptName);
                    $("#postName").val(data.postName);
                    //性别
                    if(data.athleteSex =='男'){
                        $("#man").attr('checked','true');
                    }else{
                        $("#woman").attr('checked','true');
                    }
                    $("#organName").val(data.organName);
                    $("#nativePlace").val(data.nativePlace);
                    $("#birthday").val(data.birthday);
                    //习惯手
                    if(data.hand == "右手"){
                        $("#right").attr('checked','true');
                    }else{
                        $("#left").attr('checked','true');
                    }
                    userPhto = data.usPhoto;
                    //alert(data.usPhoto);
                    $("#play").val(data.play);
                    $("#usEmail").val(data.usEmail);
                    $("#club").val(data.club);
                    $("#trainingYears").val(data.trainingYears);
                    $("#joinTime").val(data.joinTime);
                    $("#level").val(data.level);
                    $("#coachId").val(data.coachId);//现教练员
                    $("#graduateSchool").val(data.graduateSchool);
                    $("#education").val(data.education);
                    //layer.msg(data.education);
                    $("#family").val(data.family);

                    $("#bestResult").val(data.bestResult);
                    $("#athleteExp").val(data.athleteExp);
                    $("#phone").val(data.phone);
                    $("#addr").val(data.addr);
                    $("#mentality").val(data.mentality);
                    $("#usId").val(data.usId);
                    $("#usName").val(data.usName);
                    $("#usPass").val(data.usPass);
                    $("#tactics").val(data.tactics);
                    $("#mentality").val(data.mentality);
                    $("#technical").val(data.technical);
                    $("#oldCoach").val(data.oldCoach);
                    $("#nativePlace").val(data.nativePlace);
                    form.render();//渲染
                }
            });

            if(state == 1){
                $("input").attr('readonly', true);//输入框为只读

                $("textarea").attr('readonly', true);//文本域为只读

                $(':radio').attr('disabled', true);//单选框为只读

                $('select').attr('disabled', true);//下拉框为只读

                $("#resetbutton").html('<div class="layui-input-block"><button class="layui-btn" id =  "clospage" >关闭</button></div>');

                $("#birthday").attr("disabled",true);
                $("#joinTime").attr("disabled",true);
                $("#trainingYears").attr("disabled",true);
                //alert("照片路径"+userPhto);
                $("#usPoto").html('<div id="usPoto" class="layui-inline"><img width="100px" height="100px" src ="..'+userPhto+'"></div>');
                //显示运动员图片
                $("#userPoto").html("");
            }
        }

</script>


</html>